package com.example.okhttptest;

import android.util.Log;

import java.io.IOException;

/**
 * @author zjh
 * Created by kys_8 on 2018/11/19.
 */
public class PingUtil {

    public static boolean ping() {
        String result = null;
        try {
            String ip = "www.baidu.com";// ping 的地址，可以换成任何一种可靠的外网
            Process p = Runtime.getRuntime().exec("ping -c 3 -w 100 " + ip);// ping网址3次
            // ping的状态
        int status = p.waitFor();

        if (status == 0){
            result = "success";
            return true;
        }else {
            result = "failed";
        }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            Log.d("----result---", "result = " + result);
        }
        return false;

    }
}
